package com.howard.app.nivada.bo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Store {
	private String name;//商场名称
	private String desc;//描述，例如：仓库：(0308)四川-成都亨得利-成都亨得利
	private String district;//所属地区
	private List<Group> groupList = new ArrayList<Group>();//每种型号的产品列表
	private List<Product> missingProductList;//缺少的型号
	
	Integer count = 0;
	Integer typeCount = 0;
	Double okRate = 0.0;
	
	public Store(){
		missingProductList = new ArrayList<Product>();
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public List<Group> getGroupList() {
		return groupList;
	}

	public void setGroupList(List<Group> groupList) {
		this.groupList = groupList;
	}

	public List<Product> getMissingProductList() {
		return missingProductList;
	}
	public void setMissingProductList(List<Product> missingProductList) {
		this.missingProductList = missingProductList;
	}
	

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Integer getTypeCount() {
		return typeCount;
	}

	public void setTypeCount(Integer typeCount) {
		this.typeCount = typeCount;
	}
	
	public Double getOkRate() {
		return okRate;
	}

	public void setOkRate(Double okRate) {
		this.okRate = okRate;
	}

	public void addProduct(Product product){
		String groupName = product.getGroupName();
		Group group = getGroup(groupName);
		if(group == null){
			group = new Group();
			group.setName(groupName);
			groupList.add(group);
		}
		group.getProductList().add(product);
		
		count += product.getCount();
		typeCount ++;
		group.setCount(group.getCount() + product.getCount());
		group.setTypeCount(group.getTypeCount() + 1);
//		System.out.println("store="+this.getName()+",product="+product.getCode()+",groupName="+groupName+",groupSize="+group.getProductList().size()+"groupCount="+group.getCount());
	}
	
	public Group getGroup(String groupName){
		for(Group group: groupList){
			if(groupName.equals(group.getName())){
				return group;
			}
		}
		return null;
	}
	
}
